#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "MatrixKey.h"

unsigned char KeyNum;
unsigned int password;
unsigned int count;

// 密码锁（1602显示）

void main(){
	
	LCD_Init();
	LCD_ShowString(1,1,"Password:"); 
	while(1) {
		KeyNum = MatrixKey();
		if (KeyNum > 0 && KeyNum <= 10 && count++ < 4) {

			password *= 10;
			password += KeyNum % 10;
			
			LCD_ShowNum(2,1,password,4);
			
		}
		
		if (KeyNum == 11) {
			if (password == 6666) {
				LCD_ShowString(1,14,"OK!");
				Delay(500);
				LCD_ShowString(1,14,"   "); 
				password= 0;
				count = 0;
				LCD_ShowNum(2,1,password,4);
			} else {
				LCD_ShowString(1,14,"ERR"); 
				Delay(500);
				LCD_ShowString(1,14,"   "); 
				password= 0;
				count = 0;
				LCD_ShowNum(2,1,password,4);
			}
		}
		
		if (KeyNum == 12) {
			LCD_ShowString(1,14,"   "); 
			password = 0;
			count = 0;
			LCD_ShowNum(2,1,password,4);
		}
	}
	
}